import router from './router'
import store from './store'
import {getStorage} from './util/Cookies'

router.beforeEach((to, from, next) => {
  /* 显示加载中动画 */
  store.dispatch('updateLoadingStatus', true)
  let wifiPageUid = getStorage('updateUserId')
  if (wifiPageUid === null) {
    if (to.path === '/login' || to.path.indexOf('REGIST') > -1 || to.path.indexOf('FORGETPWD') > -1) {
      console.log('next')
    } else {
      console.log('next login')
      next('/login')
    }
  } else {
    if (to.path === '/login' || to.path.indexOf('REGIST') > -1 || to.path.indexOf('FORGETPWD') > -1) { next({ path: '/person', replace: true }) }
    store.dispatch('updateUserId', wifiPageUid)
  }
  next()
})

router.afterEach(route => {
  /* 隐藏加载中动画 */
  store.dispatch('updateLoadingStatus', false)
})
